package com.kygeng.springframework.context.support;

import com.kygeng.springframework.beans.BeansException;
import com.kygeng.springframework.context.ApplicationEvent;

/**
 * @Title: ClassPathXmlApplicationContext
 * @Author: kygeng
 * @Package: com.kygeng.springframework.context.support
 * @Date: 2024/7/22 13:46
 * @Description: 应用上下文实现类
 */
public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext {

    private String[] configLocations;

    public ClassPathXmlApplicationContext() {
    }

    /**
     * 从 XML 中加载 BeanDefinition，并且自动刷新上下文
     *
     * @param configLocations
     * @throws BeansException
     */
    public ClassPathXmlApplicationContext(String configLocations) {
        this(new String[]{configLocations});
    }

    /**
     * 从 XML 中加载 BeanDefinition，并且自动刷新上下文
     *
     * @param configLocations
     * @throws BeansException
     */
    public ClassPathXmlApplicationContext(String[] configLocations)  {
        this.configLocations = configLocations;
        try {
            refresh();
        }catch (Exception e){
            e.printStackTrace();
        }
    }


    @Override
    protected String[] getConfigLocations() {
        return configLocations;
    }
}
